<?php 
class Zendk_Utils implements Zend_Filter_Interface{

	public function filter($value){
		/*a à ả ã á ạ ă ằ ẳ ẵ ắ ặ â ầ ẩ ẫ ấ ậ b c d đ e è ẻ ẽ é ẹ ê ề ể ễ ế ệ
		 f g h i ì ỉ ĩ í ị j k l m n o ò ỏ õ ó ọ ô ồ ổ ỗ ố ộ ơ ờ ở ỡ ớ ợ
		p q r s t u ù ủ ũ ú ụ ư ừ ử ữ ứ ự v w x y ỳ ỷ ỹ ý ỵ z*/

		$charatera = '#(à|ả|ã|á|ạ|ă|ằ|ẳ|ẵ|ắ|ặ|â|ầ|ẩ|ẫ|ấ|ậ)#imsU';
		$replaceCharatera = 'a';
		$value = preg_replace($charatera, $replaceCharatera, $value);

		$charaterd = '#(đ)#imsU';
		$replaceCharaterd = 'd';
		$value = preg_replace($charaterd,$replaceCharaterd,$value);

		$charatere = '#(è|ẻ|ẽ|é|ẹ|ê|ề|ể|ễ|ế|ệ)#imsU';
		$replaceCharatere = 'e';
		$value = preg_replace($charatere,$replaceCharatere,$value);
			
		$charateri = '#(ì|ỉ|ĩ|í|ị)#imsU';
		$replaceCharateri = 'i';
		$value = preg_replace($charateri,$replaceCharateri,$value);

		$charatero = '#(ò|ỏ|õ|ó|ọ|ô|ồ|ổ|ỗ|ố|ộ|ơ|ờ|ở|ỡ|ớ|ợ)#imsU';
		$replaceCharatero = 'o';
		$value = preg_replace($charatero,$replaceCharatero,$value);

		$charateru = '#(ù|ủ|ũ|ú|ụ|ư|ừ|ử|ữ|ứ|ự)#imsU';
		$replaceCharateru = 'u';
		$value = preg_replace($charateru,$replaceCharateru,$value);

		$charatery = '#(ỳ|ỷ|ỹ|ý|ỵ)#imsU';
		$replaceCharatery = 'y';
		$value = preg_replace($charatery,$replaceCharatery,$value);

		$charaterA = '#(À|Ả|Ã|Á|Ạ|Ă|Ằ|Ẳ|Ẵ|Ắ|Ặ|Â|Ầ|Ẩ|Ẫ|Ấ|Ậ)#imsU';
		$replaceCharaterA = 'A';
		$value = preg_replace($charaterA, $replaceCharaterA, $value);

		$charaterD = '#(Đ)#imsU';
		$replaceCharaterD = 'D';
		$value = preg_replace($charaterD,$replaceCharaterD,$value);

		$charaterE = '#(È|Ẻ|Ẻ|É|Ẹ|Ê|Ề|Ể|Ễ|Ế|Ệ)#imsU';
		$replaceCharaterE = 'E';
		$value = preg_replace($charaterE,$replaceCharaterE,$value);
			
		$charaterI = '#(Ì|Ỉ|Ĩ|Í|Ị)#imsU';
		$replaceCharaterI = 'I';
		$value = preg_replace($charaterI,$replaceCharaterI,$value);

		$charaterO = '#(Ò|Ỏ|Õ|Ó|Ọ|Ô|Ồ|Ố|Ỗ|Ổ|Ộ|Ơ|Ờ|Ở|Ỡ|Ớ|Ợ)#imsU';
		$replaceCharaterO = 'O';
		$value = preg_replace($charaterO,$replaceCharaterO,$value);

		$charaterU = '#(Ù|Ủ|Ũ|Ú|Ụ|Ư|Ừ|Ử|Ữ|Ứ|Ự)#imsU';
		$replaceCharaterU = 'U';
		$value = preg_replace($charaterU,$replaceCharaterU,$value);

		$charaterY = '#(Ỳ|Ỷ|Ỹ|Ý|Ỵ)#imsU';
		$replaceCharaterY = 'Y';
		$value = preg_replace($charaterY,$replaceCharaterY,$value);

		return  $value;
	}

	public function validateEmail($email1, $email2) {
		/**
		 Validate an email address.
		 Provide email address (raw input)
		 Returns true if the email address has the email
		 address format and the domain exists.
		 */
		$isValid = true;
		if(strpos($email1,"@")===false)
		  return false;
        $temp=explode("@",$email1);
        if(count($temp)!=2)return false;
        if(!strlen($temp[0]))return false;
        if(!strlen($temp[1]))return false;
        $temp2=explode(".",$temp[1]);
        if(count($temp2)<=1)return false;     
        if($email1!==$email2) return false;  
        $User=new Default_Model_Member();
        $user = $User->fetchAll("Email='{$email1}'");
		return ($isValid && !count($user));
			
	}

	public function validatePasswords($pass1, $pass2) {
		//if DOESN'T MATCH
		if (strpos ( $pass1, ' ' ) !== false)
			return false;
		//if are valid
		return $pass1 == $pass2 && strlen ( $pass1 ) >= 5;
	}

	public function mobileVnCheck($number){
		$number=trim($number);
		if($number[0]=='0' || strpos($number, "+84")!==false){
			if(strlen($number)>=9){
				if(strlen((int)$number)==(strlen($number)-1) || strlen((int)$number)==(strlen($number)-3)){
					return true;
				}else{
					return false;
				}
			}else {
				return false;
			}
		}else{
			return false;
		}
		
		
	}

}